package com.ciwong.epaper.modules.me.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ciwong.mobilelib.utils.ViewHolder;
import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.me.bean.WrongQuestion;

import java.util.List;

/**
 * 错题题号列表Adapter
 *
 * @author bin
 * @version ciwong v.1.0 2015/8/10 17:33
 * @since ciwong v.1.0
 */
public class WrongQuesAdapter extends BaseAdapter
{
    /**
     * 上下文对象
     */
    private Context mContext;

    private List<WrongQuestion> questionList;

    private int mCurrQuesIndex = -1;// 当前选中的题号下标

    public void setmCurrQuesIndex(int mCurrQuesIndex)
    {
        this.mCurrQuesIndex = mCurrQuesIndex;
    }

    /**
     * 构造函数
     *
     * @param context
     * @param questionList
     */
    public WrongQuesAdapter(Context context, List<WrongQuestion> questionList)
    {
        this.mContext = context;
        this.questionList = questionList;
    }

    @Override
    public int getCount()
    {
        return questionList != null ? questionList.size() : 0;
    }

    @Override
    public Object getItem(int position)
    {
        return questionList != null && !questionList.isEmpty()
                ? questionList.get(position) : null;
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View v;
        if (convertView == null)
        {
            v = View.inflate(mContext, R.layout.item_wrong_question, null);
        }
        else
        {
            v = convertView;
        }
        TextView tvClassName = ViewHolder.get(v, R.id.item_ques_no_tv);

        WrongQuestion ques = (WrongQuestion) getItem(position);
        tvClassName.setText(ques == null ? "" : ques.getShowId());

        tvClassName.setSelected(mCurrQuesIndex == position);
        return v;
    }
}
